/*
 * Copyright (C) 2017-2021
 * All rights reserved, Designed By
 * Copyright authorization contact 18814114118
 */
package com.shop.cereshop.business.service.shop.impl;

import com.shop.cereshop.business.dao.shop.CereShopBrandDAO;
import com.shop.cereshop.business.service.shop.CereShopBrandService;
import com.shop.cereshop.commons.domain.shop.CereShopBrand;
import com.shop.cereshop.commons.exception.CoBusinessException;
import com.shop.cereshop.commons.utils.EmptyUtils;
import com.shop.cereshop.commons.utils.TimeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 品牌店铺认证服务实现类
 */
@Service
public class CereShopBrandServiceImpl implements CereShopBrandService {

    @Autowired
    private CereShopBrandDAO cereShopBrandDAO;

    @Override
    public CereShopBrand findByShopId(Long shopId) {
        if (EmptyUtils.isEmpty(shopId)) {
            return null;
        }
        return cereShopBrandDAO.findByShopId(shopId);
    }

    @Override
    public void insert(CereShopBrand cereShopBrand) throws CoBusinessException {
        if (EmptyUtils.isEmpty(cereShopBrand)) {
            throw new CoBusinessException("品牌认证信息不能为空");
        }
        if (EmptyUtils.isEmpty(cereShopBrand.getShopId())) {
            throw new CoBusinessException("店铺ID不能为空");
        }
        if (EmptyUtils.isEmpty(cereShopBrand.getBrandName())) {
            throw new CoBusinessException("品牌名称不能为空");
        }

        String time = TimeUtils.yyMMddHHmmss();
        cereShopBrand.setCreateTime(time);
        cereShopBrand.setUpdateTime(time);
        cereShopBrand.setBrandStatus(1);

        cereShopBrandDAO.insert(cereShopBrand);
    }

    @Override
    public void updateByPrimaryKey(CereShopBrand cereShopBrand) throws CoBusinessException {
        if (EmptyUtils.isEmpty(cereShopBrand)) {
            throw new CoBusinessException("品牌认证信息不能为空");
        }
        if (EmptyUtils.isEmpty(cereShopBrand.getBrandId())) {
            throw new CoBusinessException("品牌认证ID不能为空");
        }

        cereShopBrand.setUpdateTime(TimeUtils.yyMMddHHmmss());
        cereShopBrandDAO.updateByPrimaryKey(cereShopBrand);
    }

    @Override
    public void deleteByShopId(Long shopId) throws CoBusinessException {
        if (EmptyUtils.isEmpty(shopId)) {
            throw new CoBusinessException("店铺ID不能为空");
        }
        cereShopBrandDAO.deleteByShopId(shopId);
    }
}
